{include(header)}
<style>
.me_div{float:left;width:90%;margin-top:20px}
.me_div li{float:left;padding:8px 0px 5px 20px;clear:both;}
.me_div .x_tit{font-weight:bold}
.me_div1{float:left;width:90%;margin-top:20px}
.me_div1 li{float:left;padding:8px 0px 5px 20px;clear:both}
.me_div1 .x_tit{font-weight:bold}
.me_div2{float:left;width:90%}
.me_div2 li{float:left;padding:8px 0px 5px 67px;clear:both;color:#888888}
.me_div2 .x_sel{background:url(images/arrow.gif) no-repeat 55px 12px}
.me_div2 .x_sel1{color:#000000}
</style>
<div class="pMain" id="id_main" style="width:100%">
{if($user_info['grade']['val']<1)}
	当前授权级别:{$user_info['grade']['name']}，无法在线升级，提升级别
{else}
	<div class="me_div" id="id_down">
	<li class="x_tit">第一步，下载升级包</li>
	<li>方法一：<a href="javascript:thisjs.down()" style="color:#004499">在线下载</a> <span class="pBeta">(推荐)</span></li>
	<li>方法二：<a href="{$down_url}" style="color:#004499" target="_blank">下载到本地</a>  <span class="pBeta">(需要解压按说明操作)</span></li>
	{if($package == true)}
		<li>发现已经存在升级包，<a href="javascript:thisjs.install();" style="color:#004499">直接升级</a></li>
	{else if($package_zip == true)}
		<li>发现已经存在压缩升级包，<a href="javascript:thisjs.install();" style="color:#004499">直接解压</a></li>
	{/if}
	</div>
	<div id="id_install" style="display:none" style="width:100%">
		<div class="me_div1">
		<li class="x_tit">第二步，升级系统&nbsp;&nbsp;<span style="color:#888">(请点击开始升级继续)</span></li>
		<li style="padding-left:67px"><a href="javascript:thisjs.start();" style="color:#004499">开始升级</a></li>
		</div>
		<div class="me_div2" id="id_step">
		</div>
	</div>
{/if}
</div>
<script>
var thisjs = new function() {
	this.steps = [];
	this.step = 0;
	this.down = function() {
		kj.ajax.get("{fun_get::url(array('app_act'=>'down'))}&zipname={$zipname}",function(data){
			var obj_data = kj.json(data);
			if(obj_data.isnull) {
				alert("下载失败");
			} else {
				if('code' in obj_data && obj_data.code=='0') {
					thisjs.install();
				} else {
					if('msg' in obj_data) {
						alert(obj_data.msg);
					} else {
						alert("下载失败");
					}
				}
			}
		});
	}
	this.install = function() {
		kj.hide("#id_down");
		kj.show("#id_install");
		kj.ajax.get("{fun_get::url(array('app_act'=>'install_steps'))}&zipname={$zipname}",function(data){
			var obj_data = kj.json(data);
			if(obj_data.isnull) {
				alert("升级失败");
			} else {
				if('code' in obj_data && obj_data.code=='0') {
					var html = '';
					thisjs.steps = [];
					for(var i=0;i<obj_data.steps.length;i++){
						html += "<li id='id_step_" + i + "'>" + obj_data.steps[i].name + "</li>";
						thisjs.steps[thisjs.steps.length] = obj_data.steps[i].step;
					}
					kj.obj("#id_step").innerHTML = html;
				} else {
					if('msg' in obj_data) {
						alert(obj_data.msg);
					} else {
						alert("下载失败");
					}
				}
			}
		});
	}

	this.start = function() {
		kj.delClassName("#id_step li" , "x_sel");
		if(this.step>=this.steps.length) {
			kj.obj("#id_step").innerHTML = kj.obj("#id_step").innerHTML + "<li style='color:#ff8800'>升级完成</li>";
			kj.alert.show("升级完成");
			return;
		}
		var arr = kj.obj("#id_step li");
		kj.addClassName(arr[this.step] , 'x_sel');
		kj.ajax.get("{fun_get::url(array('app_act'=>'install'))}&zipname={$zipname}&step=" + this.step , function(data){
			var obj_data = kj.json(data);
			if(obj_data.isnull) {
				alert("升级失败");
			} else {
				if('code' in obj_data && obj_data.code=='0') {
					kj.addClassName("#id_step_" + thisjs.step, 'x_sel1');
					thisjs.step++;
					thisjs.start();
				} else {
					if('msg' in obj_data) {
						alert(obj_data.msg);
					} else {
						alert("升级失败");
					}
				}
			}

		});
	}
}
</script>
{include(footer)}